﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using InstrumentCheck.Module;
using InstrumentCheck.BLL;

namespace InstrumentCheck.WebAppUI
{
    public partial class Site1 : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                if (Session["UserInfo"] == null)
                    return;
                User user = Session["UserInfo"] as User;
                lblUser.Text = "使用者：" + user.EmpChineseName; ;
                BindMenu();
            }
        }

        private void BindMenu()
        {
            List<ModuleProgram> list = Setting_bll.GetMenuBll();
            foreach (ModuleProgram module in list)
            {
                if (module.ParentNO != 0)
                    continue;
                TreeNode tnode = new TreeNode();
                tnode.Text = module.ModuleName;
                BindSubMenu(module.ModuleNO, tnode, list);
                tnode.ChildNodes.Add(tnode);
                tvMenu.Nodes.Add(tnode);
            }
        }

        private void BindSubMenu(int ModuleNO, TreeNode tnode, List<ModuleProgram> listAll)
        {
            foreach (ModuleProgram modulerow in listAll)
            {
                if (modulerow.ParentNO != ModuleNO)
                    continue;
                TreeNode childNode = new TreeNode();
                childNode.Text = modulerow.ModuleName;
                childNode.Value = modulerow.ModuleURL;
                childNode.NavigateUrl = modulerow.ModuleURL;
                BindSubMenu(modulerow.ModuleNO, childNode, listAll);
                tnode.ChildNodes.Add(childNode);
            }
        }
    }
}
